﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using DiscoveryLogic.Analytics.DataObjects;
using DiscoveryLogic.Analytics.DataObjects.Rules;
using DiscoveryLogic.Common.Utilities.TextMatch;
using DiscoveryLogic.Workflows.Components.Entities.Documents;
using Document=DiscoveryLogic.Analytics.DataObjects.Document;

namespace DiscoveryLogic.Analytics.BusinessLogic.Links
{
    public class DocumentDistanceCalc : IEntityLinker
    {
        #region fields
        #endregion

        #region Implementation of IEntityLinker
        /// <summary>
        /// 
        /// </summary>
        public List<string> ArgNames
        {
            get
            {
                List<string> argNames=new List<string>();
                argNames.Add("DocContentField");
                return argNames;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="srcEntityType"></param>
        /// <param name="tgtEntityType"></param>
        /// <param name="bindings"></param>
        public void InitBindings(Type srcEntityType, Type tgtEntityType, Dictionary<string, ArgumentFieldBinding> bindings)
        {
            
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="entity1"></param>
        /// <param name="entity2"></param>
        /// <returns></returns>
        public double? CalculateDistance(EntityBase entity1, EntityBase entity2)
        {
            if(entity1 is Document && entity2 is Document)
            {
                string docContent1 = ((Document) entity1).DocContent;
                string docContent2 = ((Document) entity2).DocContent;
                DocSimiliarityUtil docSimilarity=new DocSimiliarityUtil(docContent1, docContent2);
                return docSimilarity.GetDocDistance();
            }
            else
                return null;
        }

        #endregion
    }
}
